package com.kehutong.help.admin;

import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import com.kehutong.common.util.Token;
import com.kehutong.help.entity.Help;
import com.kehutong.help.service.HelpService;

/**
 * 管理后台-消息管理
 */
@MvcAction
@ReqMapping("/admin/crm/help")
public class HelpController {

    @Inject
    private HelpService helpService;

    // @HasPermission("crm:help:view")
    @ReqMapping("/list")
    public Object list(JSONObject jsonObject) {

        return helpService.list(jsonObject);
    }

    @Bean(newInstance=true, copy=true)
    // @HasPermission("crm:help:edit")
    @ReqMapping("/save")
    public Object save(Help help, Token token) {

        help.setReleaseUserId(token.getUuid());
        help.setReleaseUserName(token.getUsername());
        return helpService.save(help);
    }

//    @HasPermission("crm:help:edit")
    @ReqMapping("/setStatus")
    public Object setStatus(Help help) {
        help.setShowStatus(!help.isShowStatus());
        helpService.update(help);
        return Result.success();
    }


    @Bean(copy=true)
    // @HasPermission("crm:help:edit")
    @ReqMapping("/update")
    public Object update(Help help) {

        return helpService.update(help);
    }

    // @Bean(copy = true)
    // @HasPermission("crm:help:edit")
    @ReqMapping("/delete")
    public Object delete(Help help) {

        return helpService.delete(help);
    }

    @ReqMapping("/get")
    public Object get(Help help) {

        return Result.success(help);
    }

}
